<?php
class MessengersController extends AppController
{
	
	var $name = 'Messengers';
	var $helpers = array('Html', 'Form', 'Javascript');
	var $layout = 'admin';
	
	function index()
	{
		$this->paginate = array('limit' => 6, 'page' => 1);
		$messenger = $this->paginate('Messenger');
		$this->set('messenger', $messenger);
	}
	
	function add()
	{
		if(! empty ($this->data))
		{
			if($this->Messenger->save ($this->data))
			{
				$this->Session->setFlash (__ ('The Messenger has been saved', true));
				$this->redirect (array('action' => 'index'));
			}else
			{
				$this->Session->setFlash (__ ('The Messenger could not be saved. Please, try again.', true));
			}
		}
	}
	
	function edit($id = null)
	{
		if(! $id && empty ($this->data))
		{
			$this->Session->setFlash (__ ('Invalid Messenger', true));
			$this->redirect (array('action' => 'index'));
		}
		if(! empty ($this->data))
		{
			if($this->Messenger->save ($this->data))
			{
				$this->Session->setFlash (__ ('The Messenger has been saved', true));
				$this->redirect (array('action' => 'index'));
			}else
			{
				$this->Session->setFlash (__ ('The Messenger could not be saved. Please, try again.', true));
			}
		}
		if(empty ($this->data))
		{
			$this->data = $this->Messenger->read (null, $id);
		}
	}
	
	function delete($id = null)
	{
		if(! $id)
		{
			$this->Session->setFlash (__ ('Invalid id for Messenger', true));
			$this->redirect (array('action' => 'index'));
		}
		if($this->Messenger->del ($id))
		{
			$this->Session->setFlash (__ ('Messenger deleted', true));
			$this->redirect (array('action' => 'index'));
		}
	}

}
?>